package cn.wuyu.baselibrary.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import cn.wuyu.baselibrary.R;


/**
 * Created by leeyinghui on 2017/8/9.
 *
 */

public class IntentUtil {

    private IntentUtil() {

    }
    /**
     * 启动activity
     */
    public static void start(Context context, Class<?> newActivity) {
        Intent it = new Intent(context,newActivity);
        context.startActivity(it);
    }
//    /**
//     * 启动activity
//     */
//    public static void start(Context context, Class<?> newActivity,Intent intent) {
////        Intent it = new Intent(context,newActivity);
//        intent.setClassName(context,newActivity)
//        it.putExtras(intent);
//        context.startActivity(it);
//    }
    /**
     * 启动activity
     */
    public static void start(Context context, Class<?> newActivity,Bundle bundle) {
        Intent it = new Intent(context,newActivity);
        it.putExtras(bundle);
        context.startActivity(it);
    }

    /**
     * 启动activity
     */
    public static void start(Activity activity, Class<?> newActivity,Bundle bundle) {
        Intent it = new Intent(activity,newActivity);
        it.putExtras(bundle);
        activity.startActivity(it);
    }
    /**
     * 启动activity
     *
     * @param activity
     * @param newActivity
     */
    public static void start(Activity activity, Class<?> newActivity) {
        Intent it = new Intent(activity, newActivity);
        activity.startActivity(it);
    }

    /**
     * 启动activity

     Map<String, Object> map= new HashMap<>();
     map.put(HotelDetailActivity.HOTEL_ID, String.valueOf(goodsVo.getUid()));
     IntentUtil.start(mActivity, AirTicketOrderConfirmActivity.class, map);

     * @param activity
     * @param newActivity
     */
    public static void start(Activity activity, Class<?> newActivity, Object param) {
        Intent it = new Intent(activity, newActivity);
        it.putExtra("params", MyJson.toJson(param));
        activity.startActivity(it);
    }

    /**
     * 启动activity, 并返回结果
     *
     * @param activity
     * @param newActivity
     * @param requestCode
     */
    public static void startForResult(Activity activity, Class<?> newActivity, int requestCode) {
        Intent it = new Intent(activity, newActivity);
        activity.startActivityForResult(it, requestCode);
    }

    /**
     * 启动activity, 并返回结果
     *
     * @param activity
     * @param newActivity
     * @param param
     * @param requestCode
     */
    public static void startForResult(Activity activity, Class<?> newActivity, Object param,
                                      int requestCode) {
        Intent it = new Intent(activity, newActivity);
        it.putExtra("params", MyJson.toJson(param));
        activity.startActivityForResult(it, requestCode);
    }

    public static void startNewActivity(Context context, Class<?> newActivity) {
        Intent intent = new Intent(context, newActivity);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    /**
     * activity跳转动画
     *
     * @param context
     * @see #setIntentTransitionLeftToRight(Activity)
     */
    public static void setIntentTransitionRightToLeft(Activity context) {
        context.overridePendingTransition(R.anim.activity_anim_in_left,
            R.anim.activity_anim_out_right);
    }

    /**
     * @param context
     * @see #setIntentTransitionRightToLeft(Activity)
     */
    public static void setIntentTransitionLeftToRight(Activity context) {
        context.overridePendingTransition(R.anim.activity_anim_in_right,
            R.anim.activity_anim_out_left);
    }

    /**
     * 返回数据到上个页面
     *
     * @param context
     * @param resultCode
     * @param data
     */
    public static void setResult(Activity context, int resultCode, Intent data) {
        context.setResult(resultCode, data);
        context.finish();
    }

    /**
     * @param context
     * @param ReqCode
     * @param newActivity
     */
    public static void startNewActivityForResult(Activity context, int ReqCode,
                                                 Class<?> newActivity) {
        Intent intent = new Intent(context, newActivity);
        context.startActivityForResult(intent, ReqCode);
        setIntentTransitionLeftToRight(context);
    }

    /**
     * @param context
     * @param ReqCode
     * @param newActivity
     */
    public static void startNewActivityForResult(Fragment context, int ReqCode,
                                                 Class<?> newActivity) {
        Intent intent = new Intent(context.getActivity(), newActivity);
        context.startActivityForResult(intent, ReqCode);
        setIntentTransitionLeftToRight(context.getActivity());
    }

    /**
     * 从fragment启动activity，参数传intent
     *
     * @param context
     * @param ReqCode
     * @param i
     */
    public static void startNewActivityForResult(Fragment context, int ReqCode,
                                                 Intent i) {
        context.startActivityForResult(i, ReqCode);
        setIntentTransitionLeftToRight(context.getActivity());
    }



}
